<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>卡拉卡-在线选号平台</title>
		<link href="/css/style.css" rel="stylesheet" type="text/css" />
		<link href="/css/win.css" rel="stylesheet" type="text/css" />
		<link href="/css/pagination.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../js/jquery-1.7.min.js"></script>
		<script type="text/javascript" src="../js/jquery.cookie.js"></script>
		<script type="text/javascript" src="../js/jquery.pagination.js"></script>
		<script type="text/javascript" src="../js/logon.js"></script>
		<script type="text/javascript" src="../js/jquery.blockUI.js"></script>
		<script type="text/javascript" src="../js/jquery.dateFormat-1.0.js"></script>
		<script type="text/javascript" src="../js/datepicker/WdatePicker.js"></script>
		<script type="text/javascript" src="../js/checkbox.js"></script>
		<script language="javascript" type="text/javascript">
			var page = 0; //页面索引初始值
			var pageSize = 9; //每页显示条数初始化，修改显示条数，修改这里即可
			$(function () {
				//initTable(10); //Load事件，初始化表格数据，页面索引为0（第一页）
				//分页，PageCount是总条目数，这是必选参数，其它参数都是可选
				$("#Pagination").pagination($!{model.get("count")}, {
					callback:PageCallback, //PageCallback() 为翻页调用次函数。
					prev_text:"上一页",
					next_text:"下一页",
					items_per_page:pageSize,
					num_edge_entries:2, //两侧首尾分页条目数
					num_display_entries:3, //连续分页主体部分分页条目数
					current_page:page, //当前页索引
				});
				//翻页调用
				function PageCallback(page,jq) {
					initTable(page);
				}
				//请求数据
				function initTable(page) {
					$.ajax({
						type:"POST",
						dataType:"text",
						url:"/order/page", //提交到一般处理程序请求数据
						data:{page:page+1,pageSize:pageSize,carrier:'$!{model.get("carrier")}',st:'$!{model.get("st")}',et:'$!{model.get("et")}',keyword:'$!{model.get("keyword")}'}, //提交两个参数：pageIndex(页面索引)，pageSize(显示条数)
						success:function(data){
						//alert(data);
							$('#list-content').html('');
							$('#list-content').html(data);
						}
					});
				}
			});
			
			function search()
			{
				$("#searchForm").submit();
			}
			
			//时间类型切换
			function doChange(obj)
			{
				$.ajax({    
			        type:'post',
			        url:'/common/datetype',
			        data:{dateType:obj.value},
			        cache:false,
			        async:false,
			        dataType:'json',
			        success:function(data){
			        	var d = jQuery.parseJSON(data);
			        	$("#st").val(data.st);
			        	$("#et").val(data.et);
			        },
			        error: function(){  //失败
				        alert('Error loading document');
				    }
			    });  
			}
			
			function detail(obj,pack)
			{
				$.ajax({    
			        type:'post',
			        url:'/order/detail',
			        data:{oid:obj},
			        cache:false,
			        async:false,
			        dataType:'json',
			        success:function(data){
			        	if(data=="error")
			        	{
			        		alert(data);
			        	}
			        	else
			        	{
			        		$("#oid").val(data.oid);
			        		$("#phonenum").val(data.phone);
			        		var orderTime = new Date();
			        		orderTime.setTime(data.order_time);
			        		var id_exp_date=new Date();
			        		id_exp_date.setTime(data.id_exp_date);
			        		$("#order_time").text($.format.date(orderTime,"yyyy/MM/dd HH:mm"));
			        		$("#phone").text(data.phone);
			        		$("#carrierName").text(data.carrier==1?"中国移动":data.carrier==2?"中国联通":"中国移动");
			        		$("#package").text(pack);
			        		$("#tariff_type").text(data.tariff_type==1?"立即生效":data.tariff_type==2?"套餐减半":data.tariff_type==3?"下月生效":"无");
			        		$("#account_name").val(data.account_name);
			        		$("#id_exp_date").text($.format.date(id_exp_date,"yyyy/MM/dd"));
			        		$("#tel").val(data.tel);
			        		$("#id_number").val(data.id_number);
			        		$("#id_address").val(data.id_address);
			        		$("#c_address").val(data.c_address);
			        		if(data.status)
			        		{
			        			if(data.status==1)
			        			{
			        				$("#status").html("<span style=\"color:red\"><b>待开卡</b></span>");
			        				$("#active").css("display","");
			        			}
			        			else if(data.status==2)
			        			{
			        				$("#status").html("<span style=\"color:green\"><b>已开卡</b></span>");
			        				$("#active").css("display","none");
			        			}
			        			else if(data.status==3)
			        			{
			        				$("#status").html("<span style=\"color:blue\"><b>已撤单</b></span>");
			        			}
			        			else if(data.status==4)
			        			{
			        				$("#status").html("<span style=\"color:red\"><b>已驳回</b></span>");
			        				$("#active").css("display","");
			        			}
			        		}
			        		$("#iccid").val("");
			        		$("#iccid").val(data.iccid);
			        		$("#remark").text("");
			        		if(data.remark)
			        		{
			        			$("#remark").html("<span style=\"color:red\"><b>"+data.remark+"</b></span>");
			        		}
							$.blockUI({ message: $('#pop')});
			        	}
			        },
			        error: function(){  //失败
				        alert('Error loading document');
				    }
			    });  
			}
			
			//（提交）编辑订单信息
			function modOrder()
			{
				var formParam = $("#infoForm").serialize();
				$.ajax({
				        type:'post',
				        url:'/sale/order/mod',
				        data:formParam,
				        cache:false,
				        async:false,
				        dataType:'json',
				        success:function(data){
				        	if(data.msg =="true" ){
				        		alert("修改成功！");
				        		$("#iccid").text("");
				        		$('#searchForm').attr("action", "/sale/order");
								$("#searchForm").target="_self";
								$("#searchForm").submit();
					        }else{
					            alert("失败，请重试！");
					        }
					        $.unblockUI();
				        },
				        error: function(){  //失败
					        alert('Error loading document');
					        $.unblockUI();
					    }
				    });
			}
			
			function hide()
			{
				$.unblockUI();
			}
			
			//支付订单,弹出层
			function payX()
			{
				var ids="";
				var i=0;  
    			$("input[name='orderid']:checked").each(function(){     
    				if(i>0)ids+=",";
    				ids+=$(this).val();
    				i++;
   				})
   				if(ids=="")
   				{
   					alert("请选择未支付订单！");
   					return;
   				}
   				$.ajax({    
			        type:'post',
			        url:'/pay',
			        data:{ids:ids},
			        cache:false,
			        async:false,
			        dataType:'json',
			        success:function(data){
			        	if(data=="error")
			        	{
			        		alert(data);
			        	}
			        	else
			        	{
			        		$("#ids").val(ids);
			        	
			        		//删除第一行外的所有行
			        		$("#payTable tr:not(:first)").remove();  
			        		
			        		var subtotal,total=0;
			        		$(data).each(function(){
								subtotal = 0;
								subtotal = this.discount+this.prestore;
								total+=subtotal;
								$("table#payTable tr:last").after("<tr><td>"+this.phone+"</td><td>￥"+(this.discount/100.00).toFixed(2)+"</td><td>￥"+(this.prestore/100.00).toFixed(2)+"</td><td align='right'>￥"+(subtotal/100.0).toFixed(2)+"</td></tr>");
							});
							//alert(total);
							$("#amount").val(total);
							$("#pay_total").html("<span style=\"color:red\"><b>￥"+(total/100.0).toFixed(2)+"</b></span>");
							$.blockUI({ message: $('#pop_pay')});
			        	}
			        },
			        error: function(){  //失败
				        alert('Error loading document');
				    }
			    });
			}
			
			//单条支付
			function payOne(obj)
			{
				$("#order"+obj).attr("checked", 'checked');
				payX();
			}
			//提交订单
			function pay_dinpay()
			{
				var amount=$("#amount").val();
				//alert(amount);
				if(amount==0)
				{
					alert("订单金额为0，无需支付！");
					$.unblockUI();
					return;
				}
				$('#payForm').attr("action", "/pay/post");
				$("#payForm").target="_blank";
				$("#payForm").submit();
				$.unblockUI();
			}
		</script>
	</head>

	<body>
		<!--首先设置一个层:-->
		<div id="pop" class="pop" style="display:none">
			<div class="pop_body">
				<div class="pop_title">订单详情</div>
				<form id="infoForm" name="infoForm" action="/sale/order/mod" method="post">
				<input type="hidden" id="oid" name="oid"/>
				<input type="hidden" id="phonenum" name="phone"/>
				<table width="100%" border="0" cellspacing="0" cellpadding="6" class="pop_table">
					<tr>
						<td width="18%" align="center" valign="top" class="line">定单时间：</td>
						<td class="line" id="order_time"></td>
						<td width="18%" class="line">订购号码：</td>
						<td class="line" id="phone"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">运营商：</td>
						<td class="line" id="carrierName"></td>
						<td class="line">套餐内容：</td>
						<td class="line" id="package"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">当月资费方式：</td>
						<td class="line" id="tariff_type"></td>
						<td class="line">开户姓名：</td>
						<td class="line"><input type="text" id="account_name" name="account_name" style="border:#999 1px solid;" maxlength="32"/></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">证件号码：</td>
						<td class="line"><input type="text" id="id_number" name="id_number" style="border:#999 1px solid;" maxlength="18"/></td>
						<td class="line">证件有效期：</td>
						<td class="line" id="id_exp_date"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">证件地址：</td>
						<td class="line"><input type="text" id="id_address" name="id_address" style="border:#999 1px solid;" maxlength="32"/></td>
						<td class="line">联系电话：</td>
						<td class="line"><input type="text" id="tel" name="tel" style="border:#999 1px solid;" maxlength="21"/></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">联系地址：</td>
						<td class="line"><input type="text" id="c_address" name="c_address" style="border:#999 1px solid;" maxlength="32"/></td>
						<td class="line">订单状态：</td>
						<td class="line" id="status"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">ICCID：</td>
						<td class="line"><input type="text" id="iccid" name="iccid" style="border:#999 1px solid;" maxlength="32"/></td>
						<td class="line">处理意见：</td>
						<td class="line" id="remark">&nbsp;</td>
					</tr>
					<tr>
						<td colspan="4">&nbsp;</td>
					</tr>
					<tr>
						<td colspan="4" align="center" class="td_n">
							<input type="button" id="active" name="Submit1" value="提交" class="login_btn"  onclick="modOrder();"/> 
							<input type="button" name="Submit2" value="关闭" class="login_btn" onclick="hide();" />
						</td>
					</tr>
				</table>
				</form>
			</div>
		</div>
		<!--支付再设置一个层:-->
		<div id="pop_pay" class="pop" style="display:none">
			<div class="pop_body">
				<div class="pop_title" id="iccid">订单支付</div>
				<form id="payForm" name="payForm" action="/pay/post" method="post" target="_blank">
				<input type="hidden" id="ids" name="ids"/>
				<input type="hidden" id="amount" name="amount"/>
				<table width="100%" border="0" cellspacing="0" cellpadding="6" class="pop_table">
					<tr>
						<td height="165" valign="top">
							<div style="overflow-y:scroll;width:100%;height:100%">
							<table id="payTable" width="100%" border="0" cellspacing="0" cellpadding="6" class="pop_table">
								<tr>
									<td width="120">号码</td>
									<td width="60">折扣价</td>
									<td width="60">预存</td>
									<td align="right">小计</td>
								</tr>
							</table>
							</div>
						</td>
					</tr>
					<tr>
						<td align="right" class="line">
							<table>
								<tr>
									<td>合计：</td>
									<td id="pay_total"></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table>
								<tr>
									<td>支付银行：</td>
									<td><select name="bank_code">
										<option value="ABC">中国农业银行</option>
										<option value="ICBC">中国工商银行</option>
										<option value="CCB">中国建设银行</option>
										<option value="BCOM">交通银行</option>
										<option value="BOC">中国银行</option>
										<option value="CMB">招商银行</option>
										<option value="CMBC">民生银行</option>
										<option value="CEBB">光大银行</option>
										<option value="CIB">兴业银行</option>
										<option value="PSBC">中国邮政</option>
										<option value="SPABANK">平安银行</option>
										<option value="ECITIC">中信银行</option>
										<option value="GDB">广东发展银行</option>
										<option value="HXB">华夏银行</option>
										<option value="SPDB">浦发银行</option>
										<option value="BEA">东亚银行</option>
										<option value="CMPAY">中国移动手机支付</option>
										<option value="ZYC">代金券支付</option>
									</select></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td height="12" align="center" class="td_n">
							<table>
								<tr>
									<td>
									<input type="button" name="pay_submit" value="确认支付" class="login_btn" onclick="pay_dinpay();" />
									<input type="button" name="pay_cancel" value="取消" class="login_btn" onclick="hide();" />
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
				</form>
			</div>
		</div>
		#include("header.html")
		<table width="100%" border="0" cellspacing="0" cellpadding="0" id="content">
			<tr><td valign="top" id="left">
			#include("menu_sale.html")
			</td>
			<td valign="top" id="right">
				<div id="order">
					<div class="title">
						<span>首页 &gt; 订单查询</span>
					</div>
					<div class="step">
						<form id="searchForm" name="searchForm" action="/sale/order" method="post">
						运营商：
						<select name="carrier">
							<option value="-1">全部</option>
							<option value="1" #if($!{model.get("carrier")}==1) selected #end>中国移动</option>
							<option value="2" #if($!{model.get("carrier")}==2) selected #end>中国联通</option>
							<option value="3" #if($!{model.get("carrier")}==3) selected #end>中国电信</option>
						</select>
						<select name="dateType" onChange="doChange(this);">
						  <option value="today" #if($!{model.get("dateType")}=="today") selected #end>今天</option>
						  <option value="yestday" #if($!{model.get("dateType")}=="yestday") selected #end>昨天</option>
						  <option value="week" #if($!{model.get("dateType")}=="week") selected #end>本周</option>
						  <option value="oneWeek" #if($!{model.get("dateType")}=="oneWeek") selected #end>一周内</option>
						  <option value="month" #if($!{model.get("dateType")}=="month") selected #end>本月</option>
						  <option value="oneMonth" #if($!{model.get("dateType")}=="oneMonth") selected #end>一月内</option>
						  <option value="period" #if($!{model.get("dateType")}=="period") selected #end>时间段</option>
						</select>
						<input type="text" id="st" name="st" value="$!{model.get("st")}" class="Wdate" style="height:20px" onfocus="WdatePicker();"/>-
						<input type="text" id="et" name="et" value="$!{model.get("et")}" class="Wdate" style="height:20px" onfocus="WdatePicker();"/>
						
						<input type="text" name="keyword" class="sou_input" value="$!{model.get("keyword")}"/>
						<input type="button" name="Submit" value="查询" class="out_btn" onclick="search();"/>
						</form>
					</div>
				</div>
				<div id="list">
					<div class="title" style="font-size:13px;font-weight:600;display:none">
						<span>查询结果</span>
					</div>
					<div class="data">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<thead>
							<tr>
								<td width="22"><input type="checkbox" onclick='checkAll(this,"orderid");'/></td>
								<td width="110">订单时间</td>
								<td width="100">手机号码</td>
								<td width="120">套餐月费</td>
								<td width="60">价格</td>
								<td width="60">预存</td>
								<td width="60">状态</td>
								<td width="50">支付</td>
								<td>处理意见</td>
								<td width="70" align="center">操作</td>
							</tr>
							</thead>
							<tbody id="list-content">
							</tbody>
							<tr>
								<td colspan="10">
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td>
												<a href="javascript:void(0);" id="btn_pay" onclick="payX();">支付</a>
											</td>
											<td><div id="Pagination" class="pagination" style="margin:4px 0 0 0"></div></td>
											<td width="80">共$!{model.get("count")}条</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</div>
				</div>
				</td></tr></table>
		#include("footer.html")
	</body>
</html>
